/**
 * 
 */
package com.whu.waterworks.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.whu.waterworks.dao.AntissepticDao;
import com.whu.waterworks.model.Antisseptic;

/**
 * @author： Joymin
 * @date：2016-4-5 下午9:04:09
 * 说明: 
 */
public class AntissepticService {
	
	private boolean flag=false;
	private AntissepticDao antissepticDao;
	
	public String addAntisseptic(Antisseptic norm,String type){
		//录入限值
		String message="";
		if(type.equals("1")){
			System.out.println("type=1");
			norm.setType("1");
			Antisseptic temp=antissepticDao.getLimitedAntisseptic();
			if(null!=temp){
				flag=antissepticDao.updateAntisseptic(norm);
			}
			else{				
				//norm.setwaterplantId("000000000000");				
				flag=antissepticDao.saveAntisseptic(norm);
			}			
		}
		//录入检测数据
		else{
			System.out.println("type=0");
			norm.setType("0");
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//设置日期格式			
			System.out.println(norm.getTime());
			if(null==norm.getId()){
				flag=antissepticDao.saveAntisseptic(norm);
			}
			else{
				flag=antissepticDao.updateAntisseptic(norm);
			}			
		}
		if(flag){
			message="提交成功！";
		}
		else{
			message="提交失败，请稍后！";
		}
		return message;
	}
	
	public Antisseptic getDataOfAntissepticNorm(){
		return antissepticDao.getLimitedAntisseptic();
	}
	
	public String delAntisseptic(Antisseptic norm){
		String message="";
		flag=antissepticDao.delAntisseptic(norm);
		if(flag){
			message="删除成功！";
		}
		else{
			message="删除失败，请稍后！";
		}
		return message;
	}

	//zhoululu
	public ArrayList<Antisseptic> getAntisseptics(String code,String starttime,String endtime){
		return (ArrayList<Antisseptic>) antissepticDao.getAntisseptics(code, starttime, endtime);
	}
	
	public Antisseptic getAntissepticById(String id){
		return antissepticDao.getAntissepticById(id);
	}	

	public AntissepticDao getAntissepticDao() {
		return antissepticDao;
	}

	public void setAntissepticDao(AntissepticDao antissepticDao) {
		this.antissepticDao = antissepticDao;
	}
}
